home *** CD-ROM | disk | FTP | other *** search
- package sun.plugin;
-
- import java.io.PrintStream;
- import java.lang.ref.ReferenceQueue;
- import java.net.URL;
- import java.security.AccessController;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.HashMap;
- import java.util.Iterator;
- import sun.applet.AppletClassLoader;
- import sun.applet.AppletPanel;
- import sun.plugin.security.PluginClassLoader;
- import sun.plugin.util.Trace;
- import sun.security.action.GetIntegerAction;
- import sun.security.action.GetPropertyAction;
-
- public class ClassLoaderInfo {
- private URL codebase;
- private String key;
- private int references = 0;
- private HashMap jars;
- private boolean locked;
- private boolean isCachable = true;
- private static boolean initialized;
- private static HashMap infos = new HashMap();
- private static int zombieLimit = 0;
- private static ArrayList zombies = new ArrayList();
- private LoaderReference loaderRef = null;
- private static ReferenceQueue refQueue = new ReferenceQueue();
- private boolean localJarsLoaded = false;
-
- private static synchronized void initialize() {
- if (!initialized) {
- initialized = true;
- reset();
- }
- }
-
- public static synchronized void reset() {
- initialized = true;
- zombieLimit = 0;
- String var0 = (String)AccessController.doPrivileged(new GetPropertyAction("javaplugin.classloader.cache.enabled"));
- if (var0 == null || var0.equals("true")) {
- zombieLimit = (Integer)AccessController.doPrivileged(new GetIntegerAction("javaplugin.classloader.cache.sizes", 4));
- }
-
- if (zombieLimit > 4) {
- zombieLimit = 4;
- }
-
- }
-
- public static synchronized void clearClassLoaderCache() {
- for(ClassLoaderInfo var1 : zombies) {
- if (var1 != null) {
- infos.remove(var1.key);
- var1.clearLoaderRef();
- }
- }
-
- zombies.clear();
- Collection var6 = infos.values();
- if (var6 != null) {
- Iterator var5 = var6.iterator();
-
- while(var5.hasNext()) {
- Object var2 = null;
- ArrayList var3 = (ArrayList)var5.next();
- if (var3 != null) {
- for(ClassLoaderInfo var7 : var3) {
- if (var7 != null) {
- var7.isCachable = false;
- }
- }
- }
- }
- }
-
- AppletPanel.flushClassLoaders();
- }
-
- public static synchronized void dumpClassLoaderCache(PrintStream var0) {
- StringBuffer var1 = new StringBuffer();
- var1.append("Dump classloader list ...\n");
- Collection var2 = infos.values();
- if (var2 != null) {
- for(ArrayList var5 : var2) {
- if (var5 != null) {
- for(ClassLoaderInfo var4 : var5) {
- if (var4 != null && var4.loaderRef != null && var4.loaderRef.get() != null) {
- boolean var7 = zombies.contains(var4);
- var1.append(" codebase=" + var4.codebase);
- var1.append(", key=" + var4.key);
- var1.append(", zombie=" + var7);
- var1.append(", cache=" + var4.isCachable);
- var1.append(", refcount=" + var4.references);
- var1.append(", info=" + var4);
- var1.append("\n");
- }
- }
- }
- }
- }
-
- var1.append("Done.");
- var0.println(var1.toString());
- }
-
- public static synchronized void markNotCachable(URL var0, String var1) {
- assert checkListsValidity();
-
- ClassLoaderInfo var2 = getUsableClassLoaderInfo(var1);
- if (var2 != null) {
- var2.isCachable = false;
- if (zombies.remove(var2)) {
- removeClassLoaderInfo(var2);
- }
-
- AppletPanel.flushClassLoader(var1);
- }
-
- assert checkListsValidity();
-
- }
-
- private static synchronized void removeClassLoaderInfo(ClassLoaderInfo var0) {
- ArrayList var1 = (ArrayList)infos.get(var0.key);
- if (var1 != null) {
- var1.remove(var0);
- if (var1.size() == 0) {
- infos.remove(var0.key);
- }
- }
-
- var0.clearLoaderRef();
- }
-
- private static synchronized void addClassLoaderInfo(ClassLoaderInfo var0) {
- ArrayList var1 = (ArrayList)infos.get(var0.key);
- if (var1 == null) {
- var1 = new ArrayList();
- var1.add(var0);
- infos.put(var0.key, var1);
- } else {
- var1.add(var0);
- }
-
- }
-
- private static synchronized ClassLoaderInfo getUsableClassLoaderInfo(String var0) {
- ArrayList var1 = (ArrayList)infos.get(var0);
- if (var1 != null) {
- Iterator var2 = var1.iterator();
- ClassLoaderInfo var3 = null;
-
- while(var2.hasNext()) {
- var3 = (ClassLoaderInfo)var2.next();
- if (var3.isCachable) {
- return var3;
- }
- }
- }
-
- return null;
- }
-
- public static synchronized ClassLoaderInfo find(URL var0, String var1) {
- assert checkListsValidity();
-
- initialize();
- if (var0 == null) {
- return null;
- } else {
- ClassLoaderInfo var2 = getUsableClassLoaderInfo(var1);
- if (var2 != null) {
- zombies.remove(var2);
- } else {
- var2 = new ClassLoaderInfo(var0, var1);
- addClassLoaderInfo(var2);
- }
-
- assert checkListsValidity();
-
- return var2;
- }
- }
-
- synchronized void addReference() {
- ++this.references;
- Trace.msgPrintln("classloaderinfo.referencing", new Object[]{this, String.valueOf(this.references)});
- }
-
- synchronized void removeReference() {
- --this.references;
- Trace.msgPrintln("classloaderinfo.releasing", new Object[]{this, String.valueOf(this.references)});
- if (this.references < 0) {
- throw new Error("negative ref count???");
- } else {
- if (this.references == 0) {
- addZombie(this);
- }
-
- }
- }
-
- private static synchronized void addZombie(ClassLoaderInfo var0) {
- assert checkListsValidity();
-
- AppletPanel.flushClassLoader(var0.key);
- if (zombieLimit != 0 && var0.isCachable) {
- Trace.msgPrintln("classloaderinfo.caching", new Object[]{var0});
- AppletClassLoader var1 = (AppletClassLoader)var0.loaderRef.get();
- if (var1 != null && var1.getExceptionStatus()) {
- var0.clearLoaderRef();
- }
-
- zombies.add(var0);
- cleanupZombies();
- Trace.msgPrintln("classloaderinfo.cachesize", new Object[]{new Integer(zombies.size())});
- if (zombies.size() > zombieLimit) {
- ClassLoaderInfo var2 = (ClassLoaderInfo)zombies.get(0);
- Trace.msgPrintln("classloaderinfo.num", new Object[]{String.valueOf(zombieLimit), var2});
- zombies.remove(0);
- removeClassLoaderInfo(var2);
- var2.clearLoaderRef();
- }
- } else {
- removeClassLoaderInfo(var0);
- }
-
- assert checkListsValidity();
-
- }
-
- synchronized AppletClassLoader getLoader() {
- Object var1 = null;
- if (this.loaderRef != null) {
- var1 = (AppletClassLoader)this.loaderRef.get();
- }
-
- if (var1 == null) {
- var1 = (PluginClassLoader)AccessController.doPrivileged(new 1(this));
- this.loaderRef = new LoaderReference(this, (ClassLoader)var1);
- this.jars.clear();
- this.localJarsLoaded = false;
- }
-
- return (AppletClassLoader)var1;
- }
-
- private synchronized void clearLoaderRef() {
- if (this.loaderRef != null) {
- this.loaderRef.clear();
- this.loaderRef = null;
- }
-
- }
-
- private static synchronized void cleanupZombies() {
- for(LoaderReference var0 = (LoaderReference)refQueue.poll(); var0 != null; var0 = (LoaderReference)refQueue.poll()) {
- String var1 = var0.getKey();
- ArrayList var2 = (ArrayList)infos.get(var1);
- if (var2 != null) {
- for(ClassLoaderInfo var5 : (ArrayList)var2.clone()) {
- if (var5.loaderRef == var0 && zombies.contains(var5)) {
- var2.remove(var5);
- zombies.remove(var5);
- }
- }
- }
- }
-
- }
-
- private ClassLoaderInfo(URL var1, String var2) {
- this.codebase = var1;
- this.key = var2;
- this.jars = new HashMap();
- }
-
- synchronized void addJar(String var1) {
- this.jars.put(var1, var1);
- }
-
- synchronized boolean hasJar(String var1) {
- return this.jars.get(var1) != null;
- }
-
- public boolean getLocalJarsLoaded() {
- return this.localJarsLoaded;
- }
-
- public void setLocalJarsLoaded(boolean var1) {
- this.localJarsLoaded = var1;
- }
-
- public final synchronized void lock() throws InterruptedException {
- while(this.locked) {
- this.wait();
- }
-
- this.locked = true;
- }
-
- public final synchronized void unlock() {
- this.locked = false;
- this.notifyAll();
- }
-
- public static synchronized boolean checkListsValidity() {
- Object var0 = null;
-
- for(ArrayList var3 : infos.values()) {
- if (var3 != null) {
- int var4 = 0;
-
- for(ClassLoaderInfo var6 : var3) {
- if (var6 != null && var6.isCachable) {
- ++var4;
- }
- }
-
- if (var4 > 1) {
- return false;
- }
- }
- }
-
- for(ClassLoaderInfo var7 : zombies) {
- if (var7 != null && !var7.isCachable) {
- return false;
- }
- }
-
- return true;
- }
-
- // $FF: synthetic method
- static URL access$000(ClassLoaderInfo var0) {
- return var0.codebase;
- }
-
- // $FF: synthetic method
- static ReferenceQueue access$100() {
- return refQueue;
- }
-
- // $FF: synthetic method
- static String access$200(ClassLoaderInfo var0) {
- return var0.key;
- }
- }
-